package qc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.quickconnect.ControlObject;

import ui.MainFrame;

import com.mysql.jdbc.Connection;

import controller.ServerConnectionHandler;

public class IsRoomMutedBCO implements ControlObject 
{

	@Override
	public Object handleIt(ArrayList<Object> arg0) {
		
		ServerConnectionHandler connection = (ServerConnectionHandler) arg0.get(0);
		HashMap params = (HashMap) arg0.get(arg0.size()-1);
		Connection con = (Connection) MainFrame.mainFrame.getController().getConnectionPool().getConnection();
		String session = (String) params.get("sessionId");
		java.sql.PreparedStatement selectMuted = null;
		ResultSet mutedResults = null;
		Boolean roomMuted = false;
		try {
			selectMuted = con.prepareStatement("SELECT SessionMute from Session s where s.SessionNumber = ?");
			selectMuted.setString(1, session);
			mutedResults = selectMuted.executeQuery();
			if(mutedResults.next() && mutedResults.getInt(1) == 1)
			{
				roomMuted = true;
			}
		} 
		catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		params.put("roomMuted", roomMuted);
		return params; 
	}

}
